﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ChangePassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //检查两个字段是不是有数据的。
            if (Request.Form["lb"] != null)
            {
                //有数据的时候清空所有内容。
                Response.Clear();
                string sType = Request.Form["lb"].ToString();
                //第一种类型，检查用户名是否存在
                if (sType == "change")
                {
                    //查找到的用户名大于0个
                    string sUserName=Page.User.Identity.Name;
                    string sOldPassword=Request.Form["oldpassword"].ToString();
                    string sPassword=Request.Form["password"].ToString();
                    if (Membership.ValidateUser(sUserName, sOldPassword))
                    {
                        MembershipUser mu = Membership.GetUser(sUserName);
                        mu.ChangePassword(sOldPassword, sPassword);
                        Response.Write("密码已修改");
                    }
                    else
                    {
                        Response.Write("旧密码错误");
                    }
                    Response.End();
                }               
            }
            else
            {
                if (Page.User.Identity.Name == "")
                    Response.Redirect(FormsAuthentication.LoginUrl);
            }
        }
    }
}
